<?php

namespace App\Modules\Admin\Http\Controllers\Water\Member;

use App\Exceptions\Exception;
use App\Modules\Admin\Http\Controllers\BaseController;
use App\Modules\Admin\Http\Requests\Water\UsersRequest;
use App\Modules\Admin\Services\BannerService;
use App\Modules\Admin\Services\Water\Member\UsersService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UsersController extends BaseController
{
    public function __construct(UsersService $service)
    {
        $this->service = $service;
    }
    public function create(UsersRequest $request): JsonResponse
    {
        return $this->createService($request);
    }
    public function update(UsersRequest $request): JsonResponse
    {
        return $this->updateService($request);
    }

    public function getSelectlists(Request $request) : JsonResponse
    {
        $result = $this->service->getSelectlists($request);

        return $this->successJson($result, $this->service->getError());

    }
    public function getUsersWaterLists(Request $request) : JsonResponse
    {
        $result = $this->service->getUsersWaterLists($request);
        if ($result){
            return $this->successJson($result, $this->service->getError());
        }else{
            return $this->errorJson($this->service->getError());
        }
    }
    public function getIntegraDetailList(Request $request) : JsonResponse
    {
        $result = $this->service->getUsersIntegraDetailLists($request);
        return $this->successJson($result, $this->service->getError());
    }
    public function updateUsersWater(Request $request) : JsonResponse
    {
        $result = $this->service->updateUsersWater($request->all());
        if ($result){
            return $this->successJson($result, $this->service->getError());
        }else{
            return $this->errorJson($this->service->getError());
        }
    }

    /**
     *  变更身份 权限
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function role(Request $request) : JsonResponse
    {
        $result = $this->service->rolesUser($request->all());
        if ($result){
            return $this->successJson($result, "操作成功");
        }else{
            return $this->errorJson($this->service->getError());
        }
    }



    /**
     * @param UserService $userService
     * @return mixed
     * @throws Exception
     */
    public function roles(UsersService $userService)
    {
        $id = (int)request('id');
        $role = (string)request('role','');
        $userService->role($id,$role);
        return success();
    }

    /**
     */
    public function unusual(Request $request): JsonResponse
    {
        $result = $this->service->getSelectListsUnusual();
        if ($result){
            return $this->successJson($result, $this->service->getError());
        }else{
            return $this->errorJson($this->service->getError());
        }
    }
}
